#ifndef SEGMENT_H_INCLUDED
#define SEGMENT_H_INCLUDED

#include "SegmentInventory.h"
#include <string.h>

class Segment
{
public:
    BufferFrame& getPage(unsigned index, bool exclusive);
    unsigned getPageCount();
    vector<unsigned> requestPages(unsigned min, unsigned max);
    unsigned getId();
    void unfixPage(BufferFrame& frame, bool dirty);
    ~Segment();

protected:

private:
    Segment(unsigned id, BufferManager& manager, SegmentInventory& segInventory);
    Segment(const Segment& other) = delete;

    unsigned segmentId;
    unsigned pageCount;
    vector<unsigned> pageIds;
    SegmentInventory& segmentInventory;
    BufferManager& manager;
    SEMAPHORE segmentLock;

    friend class SegmentManager;
};

#endif // SEGMENT_H_INCLUDED
